<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="textml; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>${_title}</title>

<!-- Bootstrap core CSS -->

<link href="${_css}/bootstrap.min.css" rel="stylesheet">

<link href="${_font}/css/font-awesome.min.css" rel="stylesheet">
<link href="${_css}/animate.min.css" rel="stylesheet">

<!-- Custom styling plus plugins -->
<link href="${_css}/custom.css" rel="stylesheet">
<link href="${_css}/icheck/flat/green.css" rel="stylesheet">
<link href="${_css}/datatables/tools/css/dataTables.tableTools.css"
	rel="stylesheet">
<link rel="stylesheet" href="${_css}/base.css">
<script src="${_js}/jquery.min.js"></script>
<script src="${_js}/resize.js"></script>
<script type="text/javascript" src="${_front_js}/jquery.page.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
<style>
td a {
	cursor: pointer
}
</style>
</head>


<body style="background: #F7F7F7;">
	<div class="">
		<div class="row">
			<div class="col-md-12 col-sm-12 col-xs-12">
				<div class="x_panel">
					<div class="x_title">
						<h2>未完成的还款</h2>
						<div class="clearfix"></div>
					</div>
					<div class="pull-right">
                    	<button id="query" type="button" class="btn btn-info">查询</button>
                    	<button id="export" type="button" class="btn btn-primary export">导出</button>
                    </div>
                    <form class="form-horizontal form-label-left input_mask" id="borrowUnRepayForm">
                    	<input type="hidden" id="status" name="status" value="N"/>
                    	<div class="col-md-2 col-sm-2 col-xs-6 form-group has-feedback">
                            <input type="text" class="form-control has-feedback-left" name="matchTitle" id="matchTitle" value="<#if matchTitle?exists>${matchTitle}</#if>"
                            placeholder="输入借款标题">
                        </div>
                        <form class="form-horizontal">
							<fieldset>
								<div class="control-group">
									<div class="controls" style="margin-left: 30px;">
										<div class="input-prepend input-group">
											<span class="add-on input-group-addon">
												<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
											</span>
											<input type="text" style="width: 200px" name="expectPaymentDate" id="reservation" placeholder="请选择理论还款时间段"
											class="form-control" value="" />
											<input type="text" style="width: 200px;margin-left:58px;" name="actualPaymentDate" id="reservation2" placeholder="请选择实际还款时间段" 
											class="form-control" value="" />
											</div>
										</div>
									</div>
								</div>
							</fieldset>
						</form>
                     </form>
					<div class="clearfix"></div>
					</div>
				</div>
				<div class="scroll">
					<div class="x_content">
						<table id="example" data-action="/admin/borrowPayment/listUnReturnBorrowPayment?1=1" class="table table-striped responsive-utilities jambo_table">
                        <thead>
                            <tr class="headings">
                                <th>
                                    <input type="checkbox" class="tableflat">
                                </th>
                                <th>序号</th>
								<th>借款用户</th>
								<th>借款标</th>
								<th>还款期数</th>
								<th>还款金额(￥)</th>
								<th>还款本金(￥)</th>
								<th>还款利息(￥)</th>
								<th>未还总额(￥)</th>
								<th>未还本金(￥)</th>
								<th>未还利息(￥)</th>
								<th>理论还款时间</th>
								<th>下期还款时间</th>
								<!--
								<th>逾期天数</th>
								<th>逾期利息</th>
								<th>逾期滞纳金</th>
								-->
								<th>创建时间</th>
								<th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
			                <#if (pageInfo.pageList?size > 0)>
								<#list pageInfo.pageList as model>
									<tr class="even pointer">
		                                <td class="a-center ">
		                                    <input type="checkbox" class="tableflat" data-id="${model.id}">
		                                </td>
		                                <td>
		                                	${model_index+1}
		                                </td>
		                                <td>
		                                	<#if model.borrowUserName?exists>
		                                		${model.borrowUserName}
		                                	</#if>
		                                </td>
		                                <td style="overflow:hidden;text-overflow: ellipsis;white-space: nowrap;word-break: keep-all;display: inline-block;width: 150px;">
		                                	<#if model.title?exists>
		                                		${model.title}
		                                	</#if>
		                                </td>
		                                <td>
		                                	<#if model.periodIndex?exists>
		                                		${model.periodIndex}期
		                                	</#if>
		                                </td>
		                                <td>
		                                	<#if model.paymentTotal?exists>
		                                		<#if (model.paymentTotal != 0 )>
			                                		${model.paymentTotal?string('0.00')}
			                                	<#else>
			                                	 	0.00
			                                	</#if>
		                                	</#if>
		                                </td>									
		                                <td>
		                                	<#if model.paymentFund?exists>
		                                		<#if (model.paymentFund != 0 )>
			                                		${model.paymentFund?string('0.00')}
			                                	<#else>
			                                	 	0.00
			                                	</#if>
		                                	</#if>
		                                </td>
		                                <td>
		                                	<#if model.paymentInterest?exists>
		                                		<#if (model.paymentInterest != 0 )>
			                                		${model.paymentInterest?string('0.00')}
			                                	<#else>
			                                	 	0.00
			                                	</#if>
		                                	</#if>
		                                </td>
		                                <td>
		                                	<#if model.notPaymentTotal?exists>
		                                		<#if (model.notPaymentTotal != 0 )>
			                                		${model.notPaymentTotal?string('0.00')}
			                                	<#else>
			                                	 	0.00
			                                	</#if>
		                                	</#if>
		                                </td>
		                                <td>
		                                	<#if model.notPaymentFund?exists>
		                                		<#if (model.notPaymentFund != 0 )>
			                                		${model.notPaymentFund?string('0.00')}
			                                	<#else>
			                                	 	0.00
			                                	</#if>
		                                	</#if>
		                                </td>
		                                <td>
		                                	<#if model.notPaymentInterest?exists>
		                                		<#if (model.notPaymentInterest != 0 )>
			                                		${model.notPaymentInterest?string('0.00')}
			                                	<#else>
			                                	 	0.00
			                                	</#if>
		                                	</#if>
		                                </td>
		                                <td>
		                                	<#if model.expectDate?exists>
		                                		${(model.expectDate?string("yyyy-MM-dd"))!}	       
		                                	</#if>
		                                </td>
		                                <td>
		                                	<#if model.nextPayDate?exists>
		                                		${model.nextPayDate?string("yyyy-MM-dd")}	       
		                                	</#if>
		                                </td>
		                                <!--
		                                <td>
		                                	<#if model.overdueDay?exists>
		                                		${model.overdueDay}
		                                	</#if>
		                                </td>
		                                <td>
		                                	<#if model.overdueInterest?exists>
		                                		${model.overdueInterest}
		                                	</#if>
		                                </td>
		                                <td>
		                                	<#if model.overdueFee?exists>
		                                		${model.overdueFee}
		                                	</#if>
		                                </td>
		                                -->
		                                <td>
		                                	<#if model.createTime?exists>
		                                		${(model.createTime?string("yyyy-MM-dd HH:mm:ss"))!}	       
		                                	</#if>
		                                </td>
		                                <td>
		                                	<a href="/admin/borrowPayment/listBorrowPaymentDetail?paymentId=${model.id }" target="p2p_frame">查看明细</a>
		                                </td>
		                             </tr>   
		                        </#list>
								<#else>
									<tr class="even pointer">
										<td colspan="14">无记录</td>
									</tr>
								</#if>
	                        </tbody>
	                    </table>
	                    <#if (pageInfo.pageList?size > 0)>
		                	<#include "../base/Page.ftl">
		                </#if>
		                <div id="pageCollect">
		                	<#if (pageInfo.pageList?size > 0)>
								共计：<span style="color:#1ABB9C">${pageInfo.total}</span>笔，
								本金：<span style="color:#1ABB9C">${pageInfo.sum}</span>元，
								利息：<span style="color:#1ABB9C">${pageInfo.sumFee}</span>元
			                </#if>
		                </div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script src="${_js}/bootstrap.min.js"></script>

		<!-- bootstrap progress js -->
		<script src="${_js}/progressbar/bootstrap-progressbar.min.js"
			type="text/javascript"></script>
		<script src="${_js}/nicescroll/jquery.nicescroll.min.js"
			type="text/javascript"></script>
		<!-- icheck -->
		<script src="${_js}/icheck/icheck.min.js" type="text/javascript"></script>

		<script src="${_js}/custom.js" type="text/javascript"></script>

		<!-- PNotify -->
	    <script src="${_js}/notify/pnotify.core.js" type="text/javascript"></script>
	    <script src="${_js}/notify/pnotify.buttons.js" type="text/javascript"></script>
	    <script src="${_js}/notify/pnotify.nonblock.js" type="text/javascript" ></script>
		<!-- daterangepicker -->
		<script type="text/javascript" src="${_js}/datepicker/moment.min2.js"></script>
		<script type="text/javascript" src="${_js}/datepicker/daterangepicker.js"></script>
		<script type="text/javascript" src="${_front_js}/date.js"></script>
		
		<script type="text/javascript" src="${_front_js}/layer/layer.js" ></script>
		<script type="text/javascript" src="${_front_js}/layer/extend/layer.ext.js" ></script>

		<script type="text/javascript">
			$(document).ready(function() {
				$('input.tableflat').iCheck({
					checkboxClass : 'icheckbox_flat-green',
					radioClass : 'iradio_flat-green'
				});
				$('#reservation').daterangepicker(null, function (start, end, label) {
		            //console.log(start.toISOString(), end.toISOString(), label);
		        });
		        
		        $('#reservation2').daterangepicker(null, function (start, end, label) {
		            //console.log(start.toISOString(), end.toISOString(), label);
		        });
			});
			
			//还款
	    	function repaySubmit(paymentId,borrowId){
	    		if(confirm("若借款人账户可用余额不足，系统将自动充值，是否确认还款?")){
	    			var index = layer.load(1,{shade: [0.8, '#393D49']});
		    		$.ajax({
			            type: "POST",
			            url:"/admin/borrowPayment/payment",
			            data:{
			            	"pid":paymentId,
			            	"borrowId":borrowId
			            },
			            async: false,
			            success: function(result) {
			            	layer.close(index);
			            	alert(result.msg);
			            	window.location.reload();
			            }
			        });
		        }
	    	}
	    				
			function initData(action) { 
				var reservation = $("#reservation").val();
				var reservation2 = $("#reservation2").val();
				var matchTitle = $.trim($("#matchTitle").val());
		    	var reg = /^\d{4}[-]\d{2}[-]\d{2}~\d{4}[-]\d{2}[-]\d{2}$/;
		    	if((reservation !="" && !reg.test(reservation)) || (reservation2 !="" && !reg.test(reservation2))){
					new PNotify({
				            	title: '操作提示',
				            	text: '时间格式错误！',
				            	delay: 3e3,
				            	type: 'error'
				        	});
				    return false;
				}
				var splitChar = "~";
				if(reservation !=""){
		    		if(reservation.indexOf(splitChar) != -1){
		    			var expectDateBegin = $.trim(reservation.split(splitChar)[0]);
		    			var expectDateEnd = $.trim(reservation.split(splitChar)[1]);
		    			action +="&expectDateBegin="+expectDateBegin;
		    			action +="&expectDateEnd="+expectDateEnd;
		    		}
		    	}
		    	if(reservation2 !=""){
		    		if(reservation2.indexOf(splitChar) != -1){
		    			var actualDateBegin = $.trim(reservation2.split(splitChar)[0]);
		    			var actualDateEnd = $.trim(reservation2.split(splitChar)[1]);
		    			action +="&actualDateBegin="+actualDateBegin;
		    			action +="&actualDateEnd="+actualDateEnd;
		    		}
		    	}
		    	if(matchTitle != ""){
		    		action +="&matchTitle="+matchTitle;
		    	}
				window.location.href=action;
			} 
			
			$("#export").click(function(){
				var count=0;
				var ids=new Array();
				var status = "";
				$("tbody .tableflat").each(function(){
					if($(this).parent().hasClass('checked')){
						ids[count]=$(this).attr("data-id");
						count++;
					}
				})
		    	var reservation = $("#reservation").val();
		    	var reservation2 = $("#reservation2").val();
		    	var reg = /^\d{4}[-]\d{2}[-]\d{2}~\d{4}[-]\d{2}[-]\d{2}$/;
		    	if((reservation !="" && !reg.test(reservation)) || (reservation2 !="" && !reg.test(reservation2))){
					new PNotify({
				            	title: '操作提示',
				            	text: '时间格式错误！',
				            	delay: 3e3,
				            	type: 'error'
				        	});
				    return false;
				}
				var action="/admin/export/borrow/repay/detail?ids="+ids;
				
				$("#borrowUnRepayForm").attr("method","post");
				$("#borrowUnRepayForm").attr("action",action);
				$("#borrowUnRepayForm").submit();
			});	
			
			$(".btn-info").click(function(){
			debugger;
				initData($("#example").attr('data-action'));
			});
		</script>
		
 <script language="javascript" type="text/javascript">  
    $(function () {  
		$('.headings input').on('ifChecked', function(event){
		  $("tbody :checkbox").iCheck('check');
		});

		$('.headings input').on('ifUnchecked', function(event){
		  $("tbody :checkbox").iCheck('uncheck');
		});
    });  
    
    var expectPaymentDateBegin = "<#if expectPaymentDateBegin?exists>${expectPaymentDateBegin}</#if>";
    var expectPaymentDateEnd = "<#if expectPaymentDateEnd?exists>${expectPaymentDateEnd}</#if>";
    if(expectPaymentDateBegin != "" && expectPaymentDateEnd != ""){
    	document.getElementById("reservation").value=expectPaymentDateBegin+"~"+expectPaymentDateEnd;
    }
    
    var actualPaymentDateBegin = "<#if actualPaymentDateBegin?exists>${actualPaymentDateBegin}</#if>";
    var actualPaymentDateEnd = "<#if actualPaymentDateEnd?exists>${actualPaymentDateEnd}</#if>";
    if(actualPaymentDateBegin != "" && actualPaymentDateEnd != ""){
    	document.getElementById("reservation2").value=actualPaymentDateBegin+"~"+actualPaymentDateEnd;
    }
    
</script> 		